#include "stdafx.h"
#include "wf_infototallength.h"

#include "wf_selectsingle.h"
#include "pf_modification.h"
#include "pf_snapper.h"
#include "pf_point.h"



WF_InfoTotalLength::WF_InfoTotalLength(PF_Container& container,
        PF_GraphicView& graphicView)
        :PF_ActionInterface("Info Total Length",
                    container, graphicView) {}


QAction* WF_InfoTotalLength::createGUIAction(LX_Define::ActionType /*type*/, QObject* /*parent*/) {
	// tr("Total length of selected entities")
    QAction* action = new QAction(tr("&Total length of selected entities"), NULL);
    //action->zetStatusTip(tr("Measures the total length of all selected entities"));
	action->setIcon(QIcon(":/extui/infototallength.png"));
    return action;
}

void WF_InfoTotalLength::init(int status) {
    PF_ActionInterface::init(status);
    trigger();
}


void WF_InfoTotalLength::trigger() {

    PF_DEBUG->print("PF_ActionInfoTotalLength::trigger()");

    double len = 0.0;
    for (PF_Entity* e = container->firstEntity(LX_Define::ResolveNone);
            e != NULL;
            e = container->nextEntity(LX_Define::ResolveNone)) {

        if (e->isVisible() && e->isSelected()) {
            double l = e->getLength();
            if (l<0.0) {
                len = -1.0;
                break;
            } else {
                len += l;
            }
        }
    }

    if (len>0.0) {
        PF_DIALOGFACTORY->commandMessage(
            tr("Total Length of selected entities: %1").arg(len));
    } else {
        PF_DIALOGFACTORY->commandMessage(tr("At least one of the selected "
                                            "entities cannot be measured."));
    }

    finish();
}



void WF_InfoTotalLength::updateToolBar() {
    if (PF_DIALOGFACTORY!=NULL) {
        if (!isFinished()) {
            PF_DIALOGFACTORY->requestToolBar(LX_Define::ToolBarInfo);
        } else {
            PF_DIALOGFACTORY->requestToolBar(LX_Define::ToolBarMain);
        }
    }
}


// EOF
